/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vng.zing.zprofilefrontend.common;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.json.simple.JSONObject;

/**
 *
 * @author namhh
 */
public class Util {

    public static boolean isInteger(String s) {
        try {
            Integer.parseInt(s);
        } catch (NumberFormatException e) {
            return false;
        }
        return true;
    }

    public static boolean isShort(String s) {
        try {
            Short.parseShort(s);
        } catch (NumberFormatException e) {
            return false;
        }
        return true;
    }

    public static String toJSON(Object status, Object message) {
        Map<Object, Object> map = new HashMap<Object, Object>();
        map.put("STATUS", status);
        map.put("MESSAGE", message);
        return JSONObject.toJSONString(map);
    }
    public static String toJSON(Object status, Object message,Object value) {
        Map<Object, Object> map = new HashMap<Object, Object>();
        map.put("STATUS", status);
        map.put("MESSAGE", message);
        map.put("VALUE", value);
        return JSONObject.toJSONString(map);
    }

    public static String toDate(Integer date) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
        return sdf.format(new Date(date.longValue() * 1000));
    }
}
